package org.mybatis.generator.codegen.spring.jdbc.model;

import static org.mybatis.generator.internal.util.messages.Messages.getString;

import java.util.List;

import org.mybatis.generator.api.CommentGenerator;
import org.mybatis.generator.api.FullyQualifiedTable;
import org.mybatis.generator.api.Plugin;
import org.mybatis.generator.api.dom.java.CompilationUnit;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.JavaVisibility;
import org.mybatis.generator.api.dom.java.TopLevelClass;
import org.mybatis.generator.codegen.mybatis3.model.SimpleModelGenerator;

public class RepModelGenerator extends SimpleModelGenerator {

	@Override
	public List<CompilationUnit> getCompilationUnits() {

		FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
		progressCallback.startTask(getString("Progress.31", table.toString())); //$NON-NLS-1$
		Plugin plugins = context.getPlugins();
		CommentGenerator commentGenerator = context.getCommentGenerator();

		FullyQualifiedJavaType type = new FullyQualifiedJavaType(
				introspectedTable.getExampleType());
		TopLevelClass topLevelClass = new TopLevelClass(type);
		topLevelClass.setVisibility(JavaVisibility.PUBLIC);
		commentGenerator.addJavaFileComment(topLevelClass);

		FullyQualifiedJavaType superClass = new FullyQualifiedJavaType(
				introspectedTable.getBaseRecordType());
		topLevelClass.setSuperClass(superClass);
		topLevelClass.addImportedType(superClass);
		commentGenerator.addModelClassComment(topLevelClass, introspectedTable);
		//
		List<CompilationUnit> answer = super.getCompilationUnits();
		if (context.getPlugins().modelBaseRecordClassGenerated(topLevelClass,
				introspectedTable)) {
			answer.add(topLevelClass);
		}

		return answer;

	}
}
